wayland: avoid set_cursor() when unchanged or invisible
authorwisp3rwind <wisp3rwind@posteo.eu>
Fri, 13 Nov 2020 12:01:56 +0000 (13:01 +0100)
committerwisperwind <wisp3rwind@posteo.eu>
Sat, 9 Jan 2021 10:42:59 +0000 (11:42 +0100)
In pointer_surface_update_scale(), only rescale the cursor surface when
the scale has actually changed and the cursor is on at least one output.

fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/3350

Right now, this issue is not completely understood, so it might also
involve some questionable handling of cursor surface by sway/wlroots.

However, irrespective of that issue, this patch avoids unnecessary calls to the
compositor, and there should be no drawback: Whenever the pointer enters
a new output, pointer_surface_update_scale() will be called again, such
that correct scaling of the cursor is still ensured.

There is a slight difference: When the cursor leaves the last output,
previously the image was reset to scale factor 1. Now, it keeps whatever
was last. That might be more sensible than the previous behaviour,
assuming that it's likely that when the cursor enter an output again, it
has the same scaling. Alternatively, if one cares about resource usage
at this level, it might make more sense to destroy the surface than
rescaling to 1.

gdk/wayland/gdkdevice-wayland.c

index c975c2069d82d123195f9252ef3d90b760a2ad7e..1ebc0f79dc104c3398f28193bb1a921f487126d4 100644 (file)
@@ -4312,6 +4312,9 @@ pointer_surface_update_scale (GdkDevice *device)
       return;
     }
 
+  if (!pointer->pointer_surface_outputs)
+    return;
+
   scale = 1;
   for (l = pointer->pointer_surface_outputs; l != NULL; l = l->next)
     {
@@ -4319,6 +4322,8 @@ pointer_surface_update_scale (GdkDevice *device)
       scale = MAX (scale, output_scale);
     }
 
+  if (pointer->current_output_scale == scale)
+    return;
   pointer->current_output_scale = scale;
 
   gdk_wayland_device_update_surface_cursor (device);